/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "gtest/gtest.h"
#include "ui_content.h"
#define private public
#include "interfaces/inner_api/form_render/include/form_renderer.h"
#undef private

using namespace testing;
using namespace testing::ext;

namespace OHOS::Ace {
class FormRenderDispatcherImplTest : public testing::Test {
public:
    static void SetUpTestCase() {};

    static void TearDownTestCase() {};
};

/**
 * @tc.name: FormRenderDispatcherImplTest001
 * @tc.type: FUNC
 * Function: DispatchPointerEvent
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest001, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest001");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    if (renderDispatcher != nullptr) {
        std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent = OHOS::MMI::PointerEvent::Create();
        pointerEvent->pointerAction_ = OHOS::MMI::PointerEvent::POINTER_ACTION_DOWN;
        SerializedGesture serializedGesture;
        renderDispatcher->DispatchPointerEvent(pointerEvent, serializedGesture);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest002
 * @tc.type: FUNC
 * Function: DispatchPointerEvent
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest002, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = nullptr;
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest002");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    if (renderDispatcher != nullptr) {
        std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent = OHOS::MMI::PointerEvent::Create();
        pointerEvent->pointerAction_ = OHOS::MMI::PointerEvent::POINTER_ACTION_DOWN;
        SerializedGesture serializedGesture;
        renderDispatcher->DispatchPointerEvent(pointerEvent, serializedGesture);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest003
 * @tc.type: FUNC
 * Function: DispatchPointerEvent
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest003, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest003");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    if (renderDispatcher != nullptr) {
        std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent = OHOS::MMI::PointerEvent::Create();
        pointerEvent->pointerAction_ = OHOS::MMI::PointerEvent::POINTER_ACTION_UP;
        SerializedGesture serializedGesture;
        renderDispatcher->DispatchPointerEvent(pointerEvent, serializedGesture);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest004
 * @tc.type: FUNC
 * Function: DispatchPointerEvent
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest004, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = nullptr;
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest004");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    if (renderDispatcher != nullptr) {
        std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent = OHOS::MMI::PointerEvent::Create();
        pointerEvent->pointerAction_ = OHOS::MMI::PointerEvent::POINTER_ACTION_UP;
        SerializedGesture serializedGesture;
        renderDispatcher->DispatchPointerEvent(pointerEvent, serializedGesture);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest005
 * @tc.type: FUNC
 * Function: SetObscured
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest005, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest005");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    if (renderDispatcher != nullptr) {
        renderDispatcher->SetObscured(true);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest006
 * @tc.type: FUNC
 * Function: OnAccessibilityChildTreeRegister
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest006, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest006");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    uint32_t windowId = 1;
    int32_t treeId = 11;
    int64_t accessibilityId = 111;
    if (renderDispatcher != nullptr) {
        renderDispatcher->OnAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest007
 * @tc.type: FUNC
 * Function: OnAccessibilityChildTreeDeregister
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest007, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest007");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    if (renderDispatcher != nullptr) {
        renderDispatcher->OnAccessibilityChildTreeDeregister();
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest008
 * @tc.type: FUNC
 * Function: OnAccessibilityDumpChildInfo
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest008, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = nullptr;
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest008");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    std::vector<std::string> params;
    std::vector<std::string> info;
    if (renderDispatcher != nullptr) {
        renderDispatcher->OnAccessibilityDumpChildInfo(params, info);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest009
 * @tc.type: FUNC
 * Function: OnAccessibilityDumpChildInfo
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest009, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest009");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    std::vector<std::string> params;
    std::vector<std::string> info;
    if (renderDispatcher != nullptr) {
        renderDispatcher->OnAccessibilityDumpChildInfo(params, info);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest010
 * @tc.type: FUNC
 * Function: OnAccessibilityTransferHoverEvent
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest010, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest010");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    float pointX = 1.1;
    float pointY = 2.2;
    int32_t sourceType = 1;
    int32_t eventType = 2;
    int64_t timeMs = 1000;
    if (renderDispatcher != nullptr) {
        renderDispatcher->OnAccessibilityTransferHoverEvent(pointX, pointY, sourceType, eventType, timeMs);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest011
 * @tc.type: FUNC
 * Function: DispatchSurfaceChangeEvent
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest011, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    std::shared_ptr<FormRenderer> formRenderer = nullptr;
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest011");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    float width = 11;
    float height = 22;
    if (renderDispatcher != nullptr) {
        renderDispatcher->DispatchSurfaceChangeEvent(width, height);
        flag = true;
    }
    EXPECT_TRUE(flag);
}

/**
 * @tc.name: FormRenderDispatcherImplTest012
 * @tc.type: FUNC
 * Function: DispatchSurfaceChangeEvent
 **@tc.desc: 1. system running normally
 *           2. test FormRendererDispatcherImpl
 */
HWTEST_F(FormRenderDispatcherImplTest, FormRenderDispatcherImplTest012, TestSize.Level1)
{
    std::shared_ptr<UIContent> uiContent = UIContent::Create(nullptr, nullptr);
    // std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
    // std::shared_ptr<FormRenderer> formRenderer = std::make_shared<FormRenderer>(context_, runtime_, eventHandler_);
    auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderDispatcherImplTest012");
    ASSERT_TRUE(eventRunner);
    auto eventHandler = std::make_shared<OHOS::AppExecFwk::EventHandler>(eventRunner);
    std::shared_ptr<FormRenderer> formRenderer = std::make_shared<FormRenderer>(nullptr, nullptr, eventHandler);
    sptr<FormRendererDispatcherImpl> renderDispatcher = new FormRendererDispatcherImpl(uiContent,
        formRenderer, eventHandler);
    bool flag = false;
    float width = 11;
    float height = 22;
    if (renderDispatcher != nullptr) {
        renderDispatcher->DispatchSurfaceChangeEvent(width, height);
        flag = true;
    }
    EXPECT_TRUE(flag);
}
} // namespace OHOS::Ace
